package main

import "fmt"

type Teacher struct {
	name    string
	age     int
	married bool
	sex     int8
}

// 结构体是值类型！
func main() {
	a := Teacher{"Steven", 35, true, 1}
	fmt.Printf("1. 变量 a 的内存地址：%p, 值为：%v\n\n", &a, a)
	fmt.Printf("数组型变量a的内存地址：%p \n\n", a)

	changeStructVal(a)
	fmt.Printf("2. changeStructVal函数调用之后内：变量 a 的内存地址：%p, 值为：%v\n\n", &a, a)
	changeStructPtr(&a)
	fmt.Printf("3. changeStructPtr函数调用之后内：变量 a 的内存地址：%p, 值为：%v\n\n", &a, a)
}

func changeStructVal(a Teacher) {
	fmt.Printf("--------------changeStructVal函数内：值参数a的内存地址：%p, 值为：%v \n", &a, a)
	fmt.Printf("--------------changeStructVal函数内：值参数a的内存地址：%p, \n", a) //获取不到地址
	a.name = "Josh"
	a.age = 29
	a.married = false
}

func changeStructPtr(a *Teacher) {
	fmt.Printf("--------------changeStructPtr函数内：值参数a的内存地址：%p, 值为：%v \n", &a, a)
	a.name = "Daniel" // 语法糖，(*a).name = "Daniel"
	a.age = 20
	a.married = false
}
